package com.woniuxy.controller;

import com.woniuxy.entity.Follow;
import com.woniuxy.entity.User;
import com.woniuxy.mapper.UserMapper;
import com.woniuxy.service.FollowService;
import com.woniuxy.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/life/follow")
public class FollowController {
    @Autowired
    private FollowService followServiceImpl;
    @Autowired
    private UserMapper userMapper;

    /*
    * 获取关注列表中的所有对象信息
    * */
    @GetMapping("/getFollowedList")
    public ResponseResult<List<User>> getFollowedList(@RequestParam("followerId") Integer followerId){
        List<Integer> list = followServiceImpl.getFollowedIdList(followerId);
        List<User> userList = new ArrayList<>();
        for (Integer userId : list) {
            userList.add(userMapper.findUserInfoByUserId(userId));
        }
        return ResponseResult.success(userList);
    }

    /*·
    * 关注
    * */
    @PostMapping("/add")
    public ResponseResult<Void> add(Follow follow){
        followServiceImpl.add(follow);
        return ResponseResult.success();
    }

    /*
    * 取消关注
    * */
    @DeleteMapping("/cancel")
    public ResponseResult<Void> cancel(Follow follow){
        followServiceImpl.cancel(follow);
        return ResponseResult.success();
    }
}
